package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DetectionItem;
import com.ruoyi.system.service.IDetectionItemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检测项字典Controller
 * 
 * @author ruoyi
 * @date 2025-10-22
 */
@Controller
@RequestMapping("/system/item")
public class DetectionItemController extends BaseController
{
    private String prefix = "system/item";

    @Autowired
    private IDetectionItemService detectionItemService;

    @RequiresPermissions("system:item:view")
    @GetMapping()
    public String item()
    {
        return prefix + "/item";
    }

    /**
     * 查询检测项字典列表
     */
    @RequiresPermissions("system:item:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DetectionItem detectionItem)
    {
        startPage();
        List<DetectionItem> list = detectionItemService.selectDetectionItemList(detectionItem);
        return getDataTable(list);
    }

    /**
     * 导出检测项字典列表
     */
    @RequiresPermissions("system:item:export")
    @Log(title = "检测项字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DetectionItem detectionItem)
    {
        List<DetectionItem> list = detectionItemService.selectDetectionItemList(detectionItem);
        ExcelUtil<DetectionItem> util = new ExcelUtil<DetectionItem>(DetectionItem.class);
        return util.exportExcel(list, "检测项字典数据");
    }

    /**
     * 新增检测项字典
     */
    @RequiresPermissions("system:item:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存检测项字典
     */
    @RequiresPermissions("system:item:add")
    @Log(title = "检测项字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DetectionItem detectionItem)
    {
        return toAjax(detectionItemService.insertDetectionItem(detectionItem));
    }

    /**
     * 修改检测项字典
     */
    @RequiresPermissions("system:item:edit")
    @GetMapping("/edit/{itemId}")
    public String edit(@PathVariable("itemId") Long itemId, ModelMap mmap)
    {
        DetectionItem detectionItem = detectionItemService.selectDetectionItemByItemId(itemId);
        mmap.put("detectionItem", detectionItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存检测项字典
     */
    @RequiresPermissions("system:item:edit")
    @Log(title = "检测项字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DetectionItem detectionItem)
    {
        return toAjax(detectionItemService.updateDetectionItem(detectionItem));
    }

    /**
     * 删除检测项字典
     */
    @RequiresPermissions("system:item:remove")
    @Log(title = "检测项字典", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(detectionItemService.deleteDetectionItemByItemIds(ids));
    }
}
